﻿
var winState = "0";
var EData = null;
Ext.onReady(function () {
    var PageCount = 0;   //总记录数
    var pagesize = 17;   //每页显示的记录数
    var currentpage = 1; //当前页
    var GetPage = function () {
        var config = Ext.getCmp("condit").getValue() != null ? Ext.getCmp("condit").getValue() : "";
        var re = new JsonRequest();
        re.category = CATEGORY.READONLY;
        re.params.year = Ext.getCmp("year").getValue();
        re.params.t = Ext.getCmp("searchtype").getValue();
        re.params.pagesize = pagesize;
        re.params.con = config;
        Ext.Ajax.request({
            url: Ext.getClassUrl('ProductReportView', 'GetEquipmentInfoCount'),
            success: function (re, op) {
                var reJson = Ext.decode(re.responseText);
                if (!reJson.HasError) {
                    PageCount = reJson.ResponseObject;
                    Ext.getCmp("cp").setValue(currentpage);
                    Ext.getCmp("zp").setValue(PageCount);
                }
            },
            jsonData: re
        });
    }
    var InitPage = function () {
        var config = Ext.getCmp("condit").getValue() != null ? Ext.getCmp("condit").getValue() : "";
        var re = new JsonRequest();
        re.category = CATEGORY.READONLY;
        re.params.year = Ext.getCmp("year").getValue();
        re.params.t = Ext.getCmp("searchtype").getValue();
        re.params.currentpage = currentpage;
        re.params.pagesize = pagesize;
        re.params.con = config;

        var t = new Ext.LoadMask(Ext.getBody(), { msg: "正在获取数据..." });
        t.show();
        Ext.Ajax.request({
            url: Ext.getClassUrl('ProductReportView', 'GetEquipmentInfo'),
            success: function (re, op) {
                var reJson = Ext.decode(re.responseText);
                if (!reJson.HasError) {
                    EData = reJson.ResponseObject;
                    var k = BindData(reJson.ResponseObject);
                    Ext.fly("DataList").dom.innerHTML = k;
                }
                t.hide();
            },
            jsonData: re
        });
    }

    yeardata = new Ext.data.JsonStore({
        url: Ext.getClassUrl('RecyclingView', 'GetYearTime'),
        root: 'ResponseObject',
        fields: ['yearid', 'yeartext'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            }
        }
    });
    yeardata.load();
    //布局
    new Ext.Viewport({
        layout: 'border',
        items: [{
            region: 'center',
            layout: 'border',
            border: false,
            title: '设备管理台帐',
            iconCls: 'ReportTitle-icon',
            tbar: ['日期：', { xtype: 'combo', width: 100, id: 'year',
                typeAhead: true,
                triggerAction: 'all',
                lazyRender: true,
                mode: 'local',
                store: yeardata,
                valueField: 'yearid',
                displayField: 'yeartext'

            }, '年', '-', '查询方式：', { xtype: 'combo', width: 150, id: 'searchtype',
                typeAhead: true,
                triggerAction: 'all',
                lazyRender: true,
                mode: 'local',
                store: new Ext.data.ArrayStore({
                    id: 0,
                    fields: [
                            'monthid',
                            'monthtext'
                        ],
                    data: [['1', '按编码查询'], ['2', '按存放位置查询'], ['3', '按名称查询'], ['4', '按设备状态查询'], ['5', '按生产厂家查询'], ['6', '按使用地点查询']]
                }),
                valueField: 'monthid',
                displayField: 'monthtext'
            }, { xtype: 'textfield', width: 100, id: 'condit', name: 'condit' }, { xtype: 'button', text: '查询', iconCls: 'search-icon', handler: function () {
                GetPage();
                InitPage();
            }
        },'->', '当前页：', { xtype: 'textfield', width: 60, id: 'cp' }, '总页数：', { xtype: 'textfield', width: 60, id: 'zp' },
            { xtype: 'button', iconCls: 'first-icon', text: '第一页', handler: function () { currentpage = 1; InitPage(); Ext.getCmp("cp").setValue(currentpage); } },
            { xtype: 'button', iconCls: 'previous-icon', text: '上一页', handler: function () { if ((currentpage - 1) > 0) currentpage -= 1; InitPage(); Ext.getCmp("cp").setValue(currentpage); } },
            { xtype: 'button', iconCls: 'next-icon', text: '下一页', handler: function () { if ((currentpage + 1) <= PageCount) currentpage += 1; InitPage(); Ext.getCmp("cp").setValue(currentpage); } },
            { xtype: 'button', iconCls: 'last-icon', text: '最后一页', handler: function () { currentpage = PageCount; InitPage(); Ext.getCmp("cp").setValue(currentpage); }
            },'-',{ xtype: 'button', text: '返回', height: 20, width: 50, iconCls: 'page-back-icon', handler: function () {
                window.history.back(-1);
            }
            }],
            items: [{
                region: 'center',
                title: '设备管理台帐',
                iconCls: 'DataList-icon',
                id: 'DataList',
                border: false,
                autoScroll: true,
                style: 'padding:2px',
                listeners: {
                    resize: function () {
                        GetPage();
                        InitPage();
                    }
                }
            }]
        }],
        listeners: {
            render: function () {
                Ext.getCmp("year").setValue(YearT);
                GetPage();
                InitPage();
            }
        }
    })
});


